const identifyStudentUrl = "http://localhost:8080/identify/student"
const identifyTeacherUrl = "http://localhost:8080/identify/teacher"

const header = {
    headers: {
        Authorization: localStorage.getItem("Authorization")
    }
};

function identifyStudent(){
    identify(true);
}

function identifyTeacher(){
    identify(false);
}

function identify(isStudent) {
    const username = localStorage.getItem("LoginUser");
    const code = document.getElementById("code").value;
    const realName = document.getElementById("realName").value;
    const idCard = document.getElementById("idCard").value;

    axios.post(isStudent ? identifyStudentUrl : identifyTeacherUrl,
        {
            username: username,
            code: code,
            realName: realName,
            idCard: idCard
        }, header)
        .then((response) => {
            const code = response.data.code
            if(code === 0){
                alert("认证成功")
                localStorage.setItem("userId", response.data.data.id)
                window.location.href = "../html/index.html"
            } else {
                alert("认证失败，请检查信息填写是否正确")
            }
        })
        .catch((err) => {
            alert("认证失败，" + err)
        })
}